package com.weme.common.util

import io.agora.ConnectionListener
import io.agora.chat.ChatClient
import android.util.Log

class ChatListenerManager {

    fun initListeners(onConfirm: (Boolean) -> Unit) {
//        ChatClient.getInstance().chatManager().addMessageListener { messages ->
//            messages?.forEach {
//                val builder = StringBuilder()
//                builder.append("Receive a ").append(it.type.name).append(" message from: ").append(it.from)
//                if (it.type === ChatMessage.Type.TXT) {
//                    builder.append(" content:").append((it.body as TextMessageBody).getMessage())
//                }
//               // showToast(builder.toString())
//            }
//        }
        ChatClient.getInstance().addConnectionListener(object : ConnectionListener {
            override fun onConnected() {
                Log.e("agora", "onConnected")

            }

            override fun onDisconnected(errorCode: Int) {
                onConfirm.invoke(true)
                Log.e("agora", "onDisconnected" + errorCode)
            }

            override fun onLogout(errorCode: Int) {
                super.onLogout(errorCode)
                Log.e("agora", "onLogout" + errorCode)
            }

            override fun onTokenExpired() {
                super.onTokenExpired()
                Log.e("agora", "onTokenExpired")
            }

            override fun onTokenWillExpire() {
                super.onTokenWillExpire()
                Log.e("agora", "onTokenWillExpire")
            }
        })
    }



}
